<!-- <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <button id="btn">获取时间</button>
  <script src="xhr.js"></script>
  <script>
    document.getElementById('btn').onclick = function(){
      var xhr = getXhr();
      xhr.open('get',' /api/getTime');
      xhr.send();
      xhr.onreadystatechange = function(){
        if(xhr.readyState == 4){
          alert(xhr.responseText);
        }
      }
    }
  </script>
</body>
</html> -->

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <button id="btn">获取时间</button>
  <script src="xhr.js"></script>
  <script>
    document.getElementById('btn').onclick = function(){
      var xhr = getXhr();
      //方法一 使用随机数
      xhr.open('get','/api/getTime?a='+ Math.random());
      //方法二 使用时间戳
      xhr.open('get', '/api/getTime?asdsad=' + Date.now());
      xhr.send();
      xhr.onreadystatechange = function(){
        if(xhr.readyState == 4){
          alert(xhr.responseText);
        };
      };
    };
  </script>
</body>
</html>